"""
@name : 局网扫描
@author : chenwenying
@projectname: 无重复字符的最长子串.py
@time : 2022/4/16
"""
import IPy
import subprocess

try:
    segment = input("请输入您要检测的网段：")
    ip = IPy.IP(segment)
    with open("ip.txt","w") as fp:
        with open("no_ip.txt","w") as fp1:
            for i in ip:
                cmd = subprocess.getoutput('ping -n 1 %s'%i)
                if 'TTL' in cmd:
                    fp.write(str(i)+'\n')
                else:
                    fp1.write(str(i)+'\n')
except KeyboardInterrupt as Ke:
    print(Ke)
except ValueError:
    print("该网段不合法")
